#include <bits/stdc++.h>
using namespace std;
#define int long long

int p;
signed dp[500][200005], sum[500];


signed main() {
	freopen("moon.in", "r", stdin); freopen("moon.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	int tc;
	cin >> tc >> p;
	dp[0][0] = 1;
	for (int i = 1; i <= 480; ++i) {
		for (int j = 0; j <= 480; ++j) {
			sum[j] = 0;
		}
		for (int j = 0; j <= 200000 - i * i; ++j) {
			(sum[j % i] += dp[i - 1][j]) %= p;
			dp[i][j] = sum[j % i];
		}
	}
	while (tc--) {
		int n;
		cin >> n;
		int ans = 0;
		for (int k = 1; k * k <= n; ++k) {
			if ((n - k * k) % 2 == 0)
				(ans += dp[k][(n - k * k) / 2]) %= p;
		}
		cout << ans << "\n";
	}
	return 0;
}
